package Gather.Advanced.Map集合.遍历的方式;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
//通过键找值的对象进行遍历
public class 键找值的对象遍历 {
    public static void main(String[] args) {
        //创建Map集合
        Map<String,String> map=new HashMap<>();

        //添加元素
        map.put("郭靖","黄蓉");
        map.put("韦小宝","沐剑屏");
        map.put("尹志平","小龙女");
        //通过键找值的对象
        Set<Map.Entry<String,String>> entries=map.entrySet();
        //增强for
        System.out.println("-------增加for-------");
        for (Map.Entry<String, String> entry : entries) {
            System.out.println(entry);
        }
        //迭代器
        System.out.println("-------迭代器-------");
        Iterator<Map.Entry<String, String>> it=entries.iterator();
        while(it.hasNext()){
            Map.Entry<String, String> str= it.next();
            //System.out.println(str);
        }
        //lanbd
        System.out.println("-------lanbd-------");
        //entries.forEach( stringStringEntry->System.out.println(stringStringEntry));
    }
}
